export const ParseProperty = (model, enumItems, boolItem) => {
  const modelRaw = JSON.parse(JSON.stringify(model))
  const dataType = modelRaw.dataType
  if (dataType.type == 'enum') {
    dataType.specs = {}
    enumItems.forEach((ei) => {
      dataType.specs[ei.value] = ei.name
    })
  } else if (dataType.type == 'bool') {
    dataType.specs = {
      '0': boolItem._true,
      '1': boolItem._false,
    }
  } else if (dataType.type == 'int32') {
    dataType.specs = {
      min: dataType.specs['min'],
      max: dataType.specs['max'],
    }
  } else if (dataType.type == 'float') {
    dataType.specs = {
      min: dataType.specs['min'],
      max: dataType.specs['max'],
      precision: dataType.specs['precision'],
    }
  } else if (dataType.type == 'text') {
    dataType.specs = {
      length: dataType.specs['length'],
    }
  } else if (dataType.type == 'position') {
    dataType.specs = {
      locateType: dataType.specs.locateType,
    }
  } else {
    dataType.specs = {}
  }

  const property = {
    description: modelRaw.description,
    unit: modelRaw.unit,
    iconId: modelRaw.iconId,
    identifier: modelRaw.identifier,
    name: modelRaw.name,
    dataType: dataType,
    accessMode: modelRaw.accessMode || 'r',
    sort: modelRaw.sort || 1,
		visable:  modelRaw.visable || true,
  }
  return property
}
/**
 * 根据日期类型得到相应的日期格式
 * @param {*} type
 */

export const getDateByType = () =>{
  let date = new Date()
  let y = date.getFullYear()
  let m:any = date.getMonth() + 1
  m = m < 10 ? '0' + m : m
  let d:any = date.getDate()
  d = d < 10 ? '0' + d : d
  let hh:any = date.getHours()
  hh = hh < 10 ? '0' + hh : hh
  let mm:any = date.getMinutes()
  mm = mm < 10 ? '0' + mm : mm
  let ss:any = date.getSeconds()
  ss = ss < 10 ? '0' + ss : ss
  let weeks = ['日', '一', '二', '三', '四', '五', '六']
  let day = '星期' + weeks[date.getDay()]
  return {
    year: y,
    month: m,
    date: d,
    hours: hh,
    minutes: mm,
    seconds: ss,
    day: day
  }
}